<template>
<div style="width: 100%">
  <a-card class="card" :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
           <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="学号">
              <a-input placeholder="请输入..." v-model="queryParam.xh"/>
            </a-form-item>
          </a-col>
           <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="院系">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.ssyxm" @change="yxChange">
                <a-select-option v-for="i in selectMenu.yx" :key="i.id" :value="i.dwh">{{ i.dwh+'-'+i.dwmc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <template v-if="advanced">
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="专业">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sszym">
                <a-select-option v-for="i in selectMenu.zy" :key="i.id" :value="i.zyh">{{ i.zyh}} {{ i.zymc }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="学生类别">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.xslbm">
                  <a-select-option v-for="i in TYPE0075" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}" >
            <a-form-item label="学位类别">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.pymsm">
                <a-select-option v-for="i in TYPE0347" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="是否上报">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.sfsb">
                <a-select-option value="1">是</a-select-option>
                <a-select-option value="0">否</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :sm="{span:12}" :lg="{span:12}" :xl="{span:6}">
            <a-form-item label="年级">
              <a-select :allowClear="true" showSearch optionFilterProp="children" v-model="queryParam.zsnj">
                <a-select-option v-for="i in TYPE0126" :key="i.id" :value="i.code">{{ i.name }}</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          </template>
          <a-col :sm="{span:24}" :xl="{span:advanced?24:12}" style="text-align:center">
            <a-button type="primary" @click="loadData">查询</a-button>
            <a-button type="primary" @click="handleExport">导出Excel</a-button>
            <a-button type="primary" @click="handleExport">导出PDF</a-button>
              <a-button @click="queryParam = {};$refs.table.refresh()">重置</a-button>

            <a @click="advanced = !advanced" style="margin-left: 8px">
                {{ advanced ? '收起' : '展开' }}
                <a-icon :type="advanced ? 'up' : 'down'"/>
              </a>
          </a-col>
        </a-row>
      </a-form>
    </div>
    </a-card>
    <a-card class="card" :bordered="false">
    <a-table
      ref="table"
      size="default"
      rowKey="key"
      :columns="columns"
      :loading="loading"
      :dataSource="data"
      :pagination="false"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
    </a-table>
    </a-card>
</div>
</template>

<script>
// import moment from 'moment'
import { STable } from '~'
import { mapState } from 'vuex'

const selectArr = ['TYPE0126', 'TYPE0075', 'TYPE0125', 'TYPE0072', 'TYPE0347']

export default {
  components: {
    STable
  },
  data () {
    return {
      advanced: true,
      fileList: [],
      uploading: false,
      loading: false,
      data: [],
      // 查询参数
      queryParam: {
        hzfs: 'yx',
        zsnj:''
      },
      postParams: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '学号',
          dataIndex: 'zsnj'
        },
        {
          title: '姓名',
          dataIndex: 'ksxm'
        },
        {
          title: '所属院系',
          dataIndex: 'bkyxsmc'
        },
        {
          title: '所属专业',
          dataIndex: 'bkzydm3'
        },
        {
          title: '身份证号',
          dataIndex: 'bkzydm2'
        },
        {
          title: '照片',
          dataIndex: 'pic'
        },
        {
          title: '学位类别',
          dataIndex: 'pic1'
        },{
          title: '上报状态',
          dataIndex: 'pic2'
        },{
          title: '上报年度',
          dataIndex: 'pic3'
        }
      ],
      recruitAddVisiable: false,
      recruitEditVisiable: false,
      selectMenu: {
        yx: [], // 院系
        zy: [] // 专业
      },
      recruitEditData: {},
      pagination:{
        current:1
      }
    }
  },
  computed: {
    ...mapState({
      systemInfo: state => state.app.systemInfo,
      TYPE0126: state => state.app['TYPE0126'], // 年级
      TYPE0075: state => state.app['TYPE0075'],
      TYPE0347: state => state.app['TYPE0347'],
    })
  },
  created () {
    this.initSelectMenu()
    
    selectArr.forEach(v => {
      this.$store.dispatch('app/setDictionary', v)
    })
  },
  methods: {
    initSelectMenu () {
      let allRequest = [
        this.$api.base.collegeAll()
      ]
      Promise.all(allRequest).then(res => {
        this.selectMenu = {
          yx: res[0].data
        }
        this.queryParam.bkyxsm=res[0].data[0].dwh;
        this.$api.base.majorAll({lsdwh: this.queryParam.bkyxsm}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
        this.$api.base.getSchoolYear().then(res=>{
        this.queryParam.zsnj=res.data.doctoralAdmissionYear
        this.loadData({
      pageNum:1,
      pageSize:10
    })
    })
      })
       
    },
    // 选择院系
    yxChange (code) {
      this.$set(this.queryParam, 'sszym', '')
      if(code){
      this.$api.base.majorAll({lsdwh: code}).then(res => {
        this.$set(this.selectMenu, 'zy', res.data)
      })
      }
    },
    // 加载数据
    loadData(parameter = {}) {
      if(!parameter.pageNum){
         this.pagination.current = 1
         parameter.pageNum = 1
       }
      let params = Object.assign(this.queryParam, parameter)
      this.loading = true;
      this.$api.doctorRecruit.campusQueryList(params).then(res => {
        // console.log(res)
         const pagination = { ...this.pagination
        };
        pagination.total = 0
        if (res.data && res.data.total) {
          pagination.total = res.data.total;
        }
        this.data = []
        this.pagination = pagination;
        if (res.data && res.data.rows.length) {
          this.data = res.data.rows;
        }
        this.loading = false;
      })
    },
    // 分页
			handleTableChange(pagination, filters, sorter) {
				console.log(pagination);
				const pager = { ...this.pagination
				};
				pager.current = pagination.current;
				this.pagination = pager;
				this.loadData({
					pageSize: 10,
					pageNum: pagination.current
				});
			},
    // 选择招生年度
    zsndChange () {

    },
    // 批量审核
    handleExport () {
      console.log('导出')
      this.$export('admissions/bskstjxx/export', this.queryParam)
    }
  }
}
</script>

<style lang="less" scoped>
.card{
  margin-bottom: 20px;
}
</style>
